/*
 * Copyright (c) 2001-2018 GuaHao.com Corporation Limited. All rights reserved.
 * This software is the confidential and proprietary information of GuaHao Company.
 * ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with GuaHao.com.
 */
package com.bgt.springboot.first.utils;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;

/**
 * TODO
 *      配置文件的方式是
 *        <typeHandlers>
 *         <typeHandler handler="com.greenline.eap.biz.dao.typehandler.ApprovalNoTypeHandler" javaType="java.lang.String" jdbcType="VARCHAR"/>
 *    </typeHandlers>
 *    使用的方式
 *     #{age,typeHandler=com.bgt.springboot.first.utils.MyTypeHandler}
 * @author Ricky
 * @version V1.0
 * @since 2018-08-02 16:14
 */
@MappedJdbcTypes(JdbcType.INTEGER)
public class MyTypeHandler extends BaseTypeHandler<Integer> {
    /**
     * 设置非空
     * @param preparedStatement
     * @param i
     * @param integer
     * @param jdbcType
     * @throws SQLException
     */
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, Integer integer, JdbcType jdbcType)
        throws SQLException {
        preparedStatement.setInt(i,++integer);
    }

    @Override
    public Integer getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return null;
    }

    @Override
    public Integer getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return null;
    }

    @Override
    public Integer getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return null;
    }
}
